﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace ProjectSem3
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        private dataDataContext dc = new dataDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.hienthidulieu();
            }
        }
        private void hienthidulieu()
        {
            List<Product> list = this.dc.Products.ToList();
            this.ListViewProduct.DataSource = list;
            this.ListViewProduct.DataBind();
        }

        protected void ListViewProduct_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            this.DataPagerProduct.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
            this.hienthidulieu();
        }

        protected void ListViewProduct_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            HiddenField productID = e.Item.FindControl("productID") as HiddenField;
            var img = this.dc.ImagesPros.Where(i => i.ProductID == Int32.Parse(productID.Value)).Skip(0).Take(1);
            Image image = e.Item.FindControl("image") as Image;
            foreach (var a in img)
            {
                image.ImageUrl = "~/images/Product/"+a.NameImg;
            }
        }

    }
}